Current Location: Home> Function Categories> rewinddir

rewinddir

Rewind the directory handle
Name:rewinddir
Category:Directory functions
Programming Language:php
One-line Description:Reset the directory handle.

Definition and usage

rewinddir() function resets the directory handle created by opendir() .

Example

Open a directory, list the files in it, reset the directory handle, list the files in it again, and close:

 <?php
$dir = "/images/" ;

// Open the directory and read its contents
if ( is_dir ( $dir ) ) {
  if ( $dh = opendir ( $dir ) ) {
    // List files in the images directory
    while ( ( $file = readdir ( $dh ) ) !== false ) {
      echo "filename:" . $file . "<br>" ;
    }
    rewinddir ( ) ;
    // List the files in the images directory again
    while ( ( $file = readdir ( $dh ) ) !== false ) {
      echo "filename:" . $file . "<br>" ;
    }
    closedir ( $dh ) ;
  }
}
?>

result:

 filename: cat.gif
filename: dog.gif
filename: horse.gif
filename: cat.gif
filename: dog.gif
filename: horse.gif

grammar

 rewinddir ( dir_handle ) ;
parameter describe
dir_handle

Optional. Specifies the directory handle resource that was previously opened by opendir() .

If this parameter is not specified, the last link opened by opendir() is used.

Similar Functions
Popular Articles